/**
 * JLabelSeprator.java
 * @author Lex
 * 2007-8-19 ����01:53:18
 */
package org.lex.swing.widgets;

import java.awt.BorderLayout;
import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JSeparator;

/**
 * ��������: +---------------------+ |Label ---Separator---|
 * +---------------------+
 * ����������������ʱ��������з��飬��Ƚ�ʹ�ö������TitledBorder������
 * �ָ������˵������JLabelSeparator���?�������� �������ڲ��ֹ������н���"����"�Ȳ���
 * 
 * XXX �������ֻ��Demo�汾�����еķ�����ֻ�Ǽ򵥵Ĵ��?label�У���Ҫ���������ࣺܶ 1��ˮƽ/��ֱ
 * 2�����ֺͷָ����λ�ã�LEFT/RIGHT/LEADING etc. 3��ComponentOrientation ������
 * Component.getComponentOrientation()
 */
public class JLabelSeparator extends JComponent {
	private JLabel label = null;

	public JLabelSeparator() {
		super();
		this.initialize();
	}

	public JLabelSeparator(String text) {
		super();
		this.initialize();
		this.getLabel().setText(text);
	}

	public JLabel getLabel() {
		return label;
	}

	private void initialize() {
		this.setLayout(new BorderLayout());
		label = new JLabel();
		this.add(label, BorderLayout.WEST);
		this.add(new JSeparator() {
			protected void paintComponent(Graphics g) {
				int width = this.getWidth();
				int y = this.getHeight() / 2;
				int gap = label.getIconTextGap();
				g.setColor(this.getForeground());
				g.drawLine(gap, y, width, y);
				g.setColor(this.getBackground());
				g.drawLine(gap, y + 1, width, y + 1);
			}

		}, BorderLayout.CENTER);
	}
}
